package com.ly.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ly.bean.Bis_coupon_active;
import com.ly.bean.Bis_coupon_record;
import com.ly.mapper.CouponActiveMapper;
import com.ly.util.JedisUtil;

@Service
@Transactional
public class CouponActiveService implements CouponActiveServiceImpl{
	@Autowired
	private CouponActiveMapper mapper;
	/**
	 * 查询所有
	 * @param active
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	@SuppressWarnings("rawtypes")
	public List<Map> querycouponactive(Bis_coupon_active active){
		return mapper.querycouponactive(active);
	};
	/**
	 * 删除
	 * @param active_id
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public void updatestatus(Integer active_id){
		mapper.updatestatus(active_id);
	};
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public void updaterecord(Integer active_id){
		mapper.updaterecord(active_id);
	};
	/**
	 * 添加
	 * @param active
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public void insert(Bis_coupon_active active){
		mapper.insert(active);
		
	};
	/**
	 * 添加礼券
	 * @param record
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public void insertrecord(Bis_coupon_record record){
		mapper.insertrecord(record);
	};
	/**
	 * 查询刚添加的一条数据的id
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public Integer querymaxid(){
		return mapper.querymaxid();
	};
	
	/**
	 * 查询总共有几条数据
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public Integer querycounts(){
		return mapper.querycounts();
	}
	
	/**
	 * 判断产生的美妍币是否失效2
	 */
	
	@Override
	public void taskCheckIsOld(){
		int hasDay=Integer.valueOf(JedisUtil.getString("hasDay","0"));
		System.out.println("************"+hasDay+"************");
		List<Bis_coupon_record> list=mapper.selectOldRecord(hasDay);
		if(list!=null&&list.size()>0){
			for(Bis_coupon_record record:list){
				mapper.updateRecordStatus(record.getRecord_id());
			}
		}
	}
	
	
}
